<?php
require_once 'include_dao.php';
require("PHPMailer/class.phpmailer.php"); //Importamos la función PHP class.phpmailer
ini_set("display_errors", $DISPLAY_ERROR);

function quitar_caracteres_raros($cadena){
   $caracteres = 'À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª { } « ¬  ® ¯ ° ± ² ³´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ × ÷ " \' & < >';
   $caracteres = explode(' ',$caracteres);
   $nchar      = count($caracteres);
   $base       = 0;
   while($base<$nchar){
      $cadena = str_replace($caracteres[$base],'_',$cadena);
      $base++;
   }
   return $cadena;
}


function validarFormulario(){
    
    if (!isset($_POST['txtNombre'])||$_POST['txtNombre']==""){
        echo '<span class="notification n-error">Debe diligenciar su Nombre</span>';
        return false;
    }
    if (!isset($_POST['txtEdad'])||$_POST['txtEdad']==""){
        echo '<span class="notification n-error">Debe diligenciar su Edad</span>';
        return false;
    }
    if (!isset($_POST['txtDia'])||$_POST['txtDia']==""){
        echo '<span class="notification n-error">Debe diligenciar su Fecha de nacimiento</span>';
        return false;
    }
    if (!isset($_POST['txtMes'])||$_POST['txtMes']==""){
        echo '<span class="notification n-error">Debe diligenciar su Fecha de nacimiento</span>';
        return false;
    }
    if (!isset($_POST['txtAnio'])||$_POST['txtAnio']==""){
        echo '<span class="notification n-error">Debe diligenciar su Fecha de nacimiento</span>';
        return false;
    }
    if (!isset($_POST['txtCedula'])||$_POST['txtCedula']==""){
        echo '<span class="notification n-error">Debe diligenciar el numero de Cedula</span>';
        return false;
    }
    if (!isset($_POST['txtCedula'])||$_POST['txtCedula']==""){
        echo '<span class="notification n-error">Debe diligenciar el numero de Cedula</span>';
        return false;
    }
    if (!isset($_POST['txtdir'])||$_POST['txtdir']==""){
        echo '<span class="notification n-error">Debe diligenciar su dirección</span>';
        return false;
    }
    if (!isset($_POST['txtTel'])||$_POST['txtTel']==""){
        echo '<span class="notification n-error">Debe diligenciar su numero de telefono</span>';
        return false;
    }
    if (!isset($_POST['txtCel'])||$_POST['txtCel']==""){
        echo '<span class="notification n-error">Debe diligenciar su numero de celular</span>';
        return false;
    }
    if (!isset($_POST['txtExpe'])||$_POST['txtExpe']==""){
        echo '<span class="notification n-error">Debe diligenciar su Experiencia</span>';
        return false;
    }
    if (!isset($_POST['txtDisphoraria'])||$_POST['txtDisphoraria']==""){
        echo '<span class="notification n-error">Debe diligenciar su Diponibilidad horaria</span>';
        return false;
    }
    if (!isset($_POST['txtTiempoTrabajar'])||$_POST['txtTiempoTrabajar']==""){
        echo '<span class="notification n-error">Debe diligenciar el tiempo que desea trabajar</span>';
        return false;
    }
    if($_POST['txtPrimarios']==""&&$_POST['txtSecundarios']&&$_POST['txtSuperior']&&$_POST['txtOtros'])
    {
       echo '<span class="notification n-error">Debe diligenciar su nivel de estudio</span>';
       return false; 
    }
    if(!isset($_POST['txtImgles'])||$_POST['txtImgles']=="")
    {
       echo '<span class="notification n-error">Debe diligenciar si maneja el Ingles</span>';
       return false; 
    }
    if(!isset($_POST['txtInglesPor'])||$_POST['txtInglesPor']=="")
    {
       echo '<span class="notification n-error">Debe diligenciar el porcentaje de Ingles que maneja</span>';
       return false; 
    }
    if(!isset($_POST['txtOtro'])||$_POST['txtOtro']=="")
    {
       echo '<span class="notification n-error">Debe diligenciar si maneja otro idioma</span>';
       return false; 
    }
    if(!isset($_POST['txtOtro'])||$_POST['txtOtro']=="")
    {
       echo '<span class="notification n-error">Debe diligenciar el porcentaje del dominio del otro idioma</span>';
       return false; 
    }
    
    return true;
    
}

if($_POST)
{
    if (validarFormulario())
    {
        if ($_POST['action'] == "send") 
        {

            $mail = new PHPMailer();

            $mail->Host = "localhost";
            $mail->From = DAOFactory::getTipoSeccionDAO()->load($CORREO_FROM)->uRLUsuraio;
            $mail->FromName = "The Pub";    
            $mail->Subject ='Correo Automatico ThePub';
            $mail->AddAddress(DAOFactory::getTipoSeccionDAO()->load($CORREO_HV)->uRLUsuraio);

            $body.= "<table width='100%' border='1' cellpadding='0' cellspacing='o'>";
            $body.= "<tr>";
            $body.=     " <td colspan='4' align='center'>";
            $body.=          "<h4>Mensaje Automatico The Pub</h4>";
            $body.=          "<h4>Hoja de Vida</h4>";
            $body.=     " </td>";
            $body.= "</tr>";
            $body.= "<tr>";
            $body.= "     <td>Nombre</td>";
            $body.= "     <td>".$_POST['txtNombre']."</td>";
            $body.= "     <td>Experiencia</td>";
            $body.= "     <td>".$_POST['txtExperiencia']."</td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Edad</td>";
            $body.= "      <td>".$_POST['txtEdad']."</td>";
            $body.= "      <td>Empresa</td>";
            $body.= "      <td>".$_POST['txtEmpresa']."</td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Fecha Nato</td>";
            $body.= "      <td>".$_POST['txtDia']."/".$_POST['txtMes']."/".$_POST['txtAnio']."</td>";
            $body.= "      <td>Cargo</td>";
            $body.= "      <td>".$_POST['txtCargo']."</td>";
            $body.= " </tr>";
            $body.= " <tr valign='top'>";
            $body.= "      <td>Cedula</td>";
            $body.= "      <td>".$_POST['txtCedula']."</td>";
            $body.= "      <td rowspan='2' valign='top'>Funciones</td>";
            $body.= "      <td rowspan='2'>".$_POST['txtfunciones']."</td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Dirección</td>";
            $body.= "      <td>".$_POST['txtdir']." </td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Telefono</td>";
            $body.= "      <td>".$_POST['txtTel']." </td>";
            $body.= "      <td>Tiempo en la Empresa</td>";
            $body.= "      <td>".$_POST['txtTiempoEmpresa']."(meses)</td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Celular</td>";
            $body.= "      <td>".$_POST['txtCel']." </td>";
            $body.= "      <td rowspan='2' valign='top'>Motivo del Retiro</td>";
            $body.= "      <td rowspan='2'>".$_POST['txtRetiroEmpresa']."</td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Experiencia</td>";
            $body.= "      <td>".$_POST['txtExpe']." </td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Disp. Horaria</td>";
            $body.= "      <td>".$_POST['txtDisphoraria']." </td>";
            $body.= "      <td>Empresa</td>";
            $body.= "      <td>".$_POST['txtEmpresa2']."</td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Tiempo que desea Trabajar</td>";
            $body.= "      <td>".$_POST['txtTiempoTrabajar']." </td>";
            $body.= "      <td valign='top'>Cargo</td>";
            $body.= "      <td>".$_POST['txtCargo2']."</td>";
            $body.= " </tr>";
            $body.= " <tr valign='top'>";
            $body.= "      <td rowspan='3'>Estudios</td>";
            $body.= "      <td rowspan='3'><table width='200' border='0' cellpadding='0' cellspacing='0'>";
            $body.= "         <tr>";
            $body.= "           <td >Primarios</td>";
            $body.= "           <td >".$_POST['txtPrimarios']."</td>";
            $body.= "         </tr>";
            $body.= "         <tr>";
            $body.= "           <td >Secundarios</td>";
            $body.= "           <td >".$_POST['txtSecundarios']."</td>";
            $body.= "         </tr>";
            $body.= "         <tr>";
            $body.= "           <td >Superior</td>";
            $body.= "           <td >".$_POST['txtSuperior']."</td>";
            $body.= "         </tr>";
            $body.= "         <tr>";
            $body.= "           <td >Otros</td>";
            $body.= "           <td >".$_POST['txtOtros']."</td>";
            $body.= "         </tr>";
            $body.= "      </table></td>";
            $body.= "      <td valign='top'>Funciones</td>";
            $body.= "      <td>".$_POST['txtFunciones2']."</td>";
            $body.= " </tr>";
            $body.= " <tr valign='top'>";
            $body.= "      <td>Tiempo en la Empresa</td>";
            $body.= "      <td align='left' valign='middle'>".$_POST['txtTiempoEmpresa2']." (meses) </td>";
            $body.= " </tr>";
            $body.= " <tr valign='top'>";
            $body.= "      <td rowspan='2'>Motivo del Retiro</td>";
            $body.= "      <td rowspan='2' align='right' valign='middle'>".$_POST['txtRetiroEmpresa2']." </td>";
            $body.= " </tr>";
            $body.= " <tr>";
            $body.= "      <td>Idiomas</td>";
            $body.= "      <td><table width='200' border='0'  cellpadding='0' cellspacing='0' align='left'>";
            $body.= "         <tr>";
            $body.= "           <td >".$_POST['txtImgles']."</td>";
            $body.= "           <td >".$_POST['txtInglesPor']."</td>";
            $body.= "           <td >".$_POST['txtOtro']."</td>";
            $body.= "           <td >".$_POST['txtOtroPor']."</td>";
            $body.= "         </tr>";
            $body.= "         <tr align='center'>";
            $body.= "           <td >Ingles</td>";
            $body.= "           <td >%</td>";
            $body.= "           <td >Otro</td>";
            $body.= "           <td >%</td>";
            $body.= "         </tr>";
            $body.= "     </table></td>";
            $body.= " </tr>";
            $body.= "</table>";

            $body.= "<br><i>Enviado por The Pub (c)</i>";

            
            if($_FILES['fileimg']['name']!=''){
                $nombre_archivo = quitar_caracteres_raros($_FILES['fileimg']['name']);
                $tipo_archivo   = $_FILES['fileimg']['type'];
                $tamano_archivo = $_FILES['fileimg']['size'];
                $ruta_archivo   = $_FILES['fileimg']['tmp_name'];
                
                if(!is_dir('./resources/img_cms/adjuntos/'))
                {
                    mkdir('./resources/img_cms/adjuntos/');
                }
                
                $destination = './resources/img_cms/adjuntos/';
            
                if(move_uploaded_file($ruta_archivo, $destination.$nombre_archivo)){
                    $mail->AddAttachment($destination.$nombre_archivo);
                }  
            }
            
            $mail->Body = $body;
            $mail->IsHTML(true);
            $mail->Send();
            
            echo '<span class="notification n-success">Mensaje Enviado Correctamente.</span>';
        }
    }
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Trabaje con nosotros</title>
    <link type="text/css" rel="stylesheet" href="./resources/css/styles.css">

    <script type="text/javascript">
    
    function  validarFormulario(){

        if(form.elements['txtNombre'] ==''){
            alert('Debe diligenciar su nombre');
            return false;
        }else{
            return false;
        };
    }
    
    </script>
        
		<style type="text/css">

   
                 body{
                        background-color: #FFF;
                        colbackground-cor:#000;
                        
                        }

		textarea{      
			background:url(resources/img/Campo-TextoLargo.gif) no-repeat;
                        width: 325px;
                        height: 70px;
                        padding: 5px;
                        border: none;
                    }
            
			td{
                padding: 1px;
				font-size: 11px;
                font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
							
                    }
         
			 .boton {background: url(resources/img/<?php echo Idioma("Enviar.gif","Send.gif");?>) no-repeat;
                     width: 90px;
                     height: 50px;
					 border-color:transparent;
              }
				
            #titulo {
	text-decoration: none;
	text-align: center;
	color: #3F7928;
	background: #ffffff;
	display: block;
	text-align: center;
	border-bottom: 1px solid #3F7928;
	border-top: 1px solid #3F7928;
	font-family: Georgia, "Times New Roman", Times, serif;
	font-size: 21px;
	font-weight: bold;
	font-size: 24px;
	padding: 3px;
	height: 20px;
	width: 300px;
			}
			
			         input.largo{
                background: url(resources/img/Campo-Nombre-T.con-Nosotros.gif) no-repeat;
                width: 260px;
                height: 25px;
                padding: 5px;
				border: none;
            }
			
			 input.corto{
                background: url(resources/img/Campo-Corto.gif) no-repeat;
                width: 40px;
                height: 25px;
                padding: 5px;
				border: none;
            }
			
			 input.normal{
                background: url(resources/img/Campo-Normal.gif) no-repeat;
                width: 200px;
                height: 25px;
                padding: 5px;
				border: none;
            }
			
			 input.medio{
                background: url(resources/img/Campo-Medio.gif) no-repeat;
                width: 65px;
                height: 25px;
                padding: 5px;
				border: none;
            }
			
			 .titulotexto
            {
	text-align: center;
	color: #407928;
	border-bottom: 1px solid #407928;
	border-top: 1px solid #407928;
	font-weight: bold;
	font-size: 24px;
	padding: 3px;
	font-family: Georgia, "Times New Roman", Times, serif;
            }
			
	
		
        </style>
    </head>
    <body>
        <form action="" method="post" enctype="multipart/form-data" onSubmit="validarFormulario()">
<div class="contenido">
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="5" align="center">
                  <img alt="" src="resources/img/The-pub-solo-sin-titulo.gif">
                  <div style="text-align: center; padding: 3px">
                        <span class="titulotexto">
                        <?php
                        if($_SESSION['_IDIOMA']==$IDIOMA_ESP)
                            echo "Trabaje con Nosotros";
                        else
                            echo "Be part of The Pub team";
                      ?>
                          </span>
                    </div>
              </td>
            </tr>
            
            <tr>
              <td width="10%">&nbsp;</td>
              <td width="35%">&nbsp;</td>
              <td width="10%">&nbsp;</td>
              <td width="10%">&nbsp;</td>
              <td width="35%">&nbsp;</td>
            </tr>
            <tr>
            <td>
                 <?php echo Idioma("Nombre","Name");?>
              </td>
              <td><input type="text" class="largo" id="txtNombre" name="txtNombre" /></td>
              <td>&nbsp;</td>
              <td> 
                  <?php echo Idioma("Experiencia","Experience");?>
              </td>
              <td><input type="text" class="normal" name="txtExperiencia" /></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Edad","Age");?></td>
              <td><input type="text" class="medio" name="txtEdad" /></td>
              <td>&nbsp;</td>
              <td><?php echo Idioma("Empresa","Company");?></td>
              <td><input type="text" class="normal" name="txtEmpresa" /></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Fecha Nato","Date of Birth");?></td>
              <td><input type="text" class="corto" name="txtDia" />
                /
                <input type="text" class="corto" name="txtMes" />
                /
                <input type="text" class="corto" name="txtAnio" /> 
                (dd/mm/aa)</td>
              <td>&nbsp;</td>
              <td><?php echo Idioma("Cargo","Position");?></td>
              <td><input type="text" class="normal" name="txtCargo" /></td>
            </tr>
            <tr valign="top">
              <td><?php echo Idioma("Cedula","ID");?></td>
              <td><input type="text" class="normal" name="txtCedula" /></td>
              <td rowspan="2" valign="top">&nbsp;</td>
              <td rowspan="2" valign="top"><?php echo Idioma("Funciones","Duties");?></td>
              <td rowspan="2"><textarea name="txtfunciones"></textarea></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Direccion","Address");?></td>
              <td><input type="text" class="normal" name="txtdir" /></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Telefono","Phone");?></td>
              <td><input type="text" class="normal" name="txtTel" /></td>
              <td valign="top">&nbsp;</td>
              <td valign="top"><?php echo Idioma("Tiempo en la Empresa","Work time");?></td>
              <td><input type="text" class="medio" name="txtTiempoEmpresa" />
                <?php echo Idioma("(meses)","(month)");?></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Celular","Movil");?></td>
              <td><input type="text" class="normal" name="txtCel" /></td>
              <td rowspan="2" valign="top">&nbsp;</td>
              <td rowspan="2" valign="top"><?php echo Idioma("Motvo del Retiro","Reason for the retirement");?></td>
              <td rowspan="2"><textarea name="txtRetiroEmpresa"></textarea></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Experiencia","Experience");?></td>
              <td><input type="text" class="corto" name="txtExpe" />
                <?php echo Idioma("(meses)","(month)");?></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Disp. Horaria","Availability");?></td>
              <td><input type="text" class="normal" name="txtDisphoraria" /></td>
              <td valign="top">&nbsp;</td>
              <td valign="top"><?php echo Idioma("Empresa","Company");?></td>
              <td><input type="text" class="normal" name="txtEmpresa2" /></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Tiempo que desea Trabajar","Time that wish to work");?></td>
              <td><input type="text" class="normal" name="txtTiempoTrabajar" /></td>
              <td valign="top">&nbsp;</td>
              <td valign="top"><?php echo Idioma("Cargo","Position");?></td>
              <td><input type="text" class="normal" name="txtCargo2" /></td>
            </tr>
           <tr valign="top">
              <td rowspan="3" ><?php echo Idioma("Estudios","Studies");?></td>
              <td rowspan="3"><table width="200" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td><?php echo Idioma("Primarios","Primary");?></td>
                  <td><input type="text" class="medio" name="txtPrimarios" /></td>
                </tr>
                <tr>
                  <td><?php echo Idioma("Secundarios","Secondary");?></td>
                  <td><input type="text" class="medio" name="txtSecundarios" /></td>
                </tr>
                <tr>
                  <td><?php echo Idioma("Superior","College");?></td>
                  <td><input type="text" class="medio" name="txtSuperior" /></td>
                </tr>
                <tr>
                  <td><?php echo Idioma("Otros","Others");?></td>
                  <td><input type="text" class="medio" name="txtOtros" /></td>
                </tr>
              </table></td>
              <td>&nbsp;</td>
              <td><p><?php echo Idioma("Funciones","Duties");?></p></td>
              <td align="left" valign="middle"><textarea name="txtFunciones2"></textarea></td>
            </tr>
           <tr valign="top">
             <td>&nbsp;</td>
             <td><?php echo Idioma("Tiempo en la Empresa","Work time");?></td>
             <td align="left" valign="middle"><input type="text" class="medio" name="txtTiempoEmpresa2" />
               <?php echo Idioma("(meses)","(month)");?></td>
           </tr>
           <tr valign="top">
             <td rowspan="2">&nbsp;</td>
             <td rowspan="3"><?php echo Idioma("Motivo del Retiro","Reason for the retirement");?></td>
             <td rowspan="3" align="left" valign="top"><textarea name="txtRetiroEmpresa2"></textarea></td>
           </tr>
            <tr>
              <td><?php echo Idioma("Idiomas","Languages");?></td>
              <td valign="top"><table width="200" border="0"  cellpadding="0" cellspacing="0" align="left">
                <tr>
                  <td><input type="text" class="corto" name="txtImgles" /></td>
                  <td><input type="text" class="corto" name="txtInglesPor" /></td>
                  <td><input type="text" class="medio" name="txtOtro" /></td>
                  <td><input type="text" class="corto" name="txtOtroPor" /></td>
                </tr>
                <tr align="center">
                  <td><?php echo Idioma("Ingles","English");?></td>
                  <td>%</td>
                  <td><?php echo Idioma("Otro","Other");?></td>
                  <td>%</td>
                </tr>
              </table>
               <br>
                  <br/>
              </p></td>
            </tr>
            <tr>
              <td><?php echo Idioma("Foto","Picture");?></td>
              <td><input name="fileimg"size="50" type="file" value="Examinar"></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td align="right">
                  <input type="submit" class="boton" value="" title="" />
                  <input type="hidden" name="action" value="send" />
              </td>
            </tr>
          </table>
        </div>
        </form>
    </body>
</html>
